package component.hide
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.ProgressEvent;
	import flash.net.URLLoader;
	import flash.net.URLLoaderDataFormat;
	import flash.net.URLRequest;
	import flash.utils.ByteArray;

	public class URLLoader2 extends EventDispatcher
	{
		private var _loader:URLLoader;
		
		private var _loaderType : String;
		
		private var _orgData : *;
		
		public function URLLoader2()
		{
		}
		
		public function load(url:String,type:String=null):void
		{
			_loaderType = type;
			_loader = new URLLoader();
			_loader.addEventListener(Event.COMPLETE, onLoad);
			_loader.addEventListener(ProgressEvent.PROGRESS,loadPregress);
			
			if(type)
			{
				_loader.dataFormat = type;
			}
			
			_loader.load(new URLRequest(url));
		}
		
		private function loadPregress(evt : ProgressEvent) : void
		{
			this.dispatchEvent(evt);
		}
		
		private function onLoad(event:Event):void
		{	
			_loader.removeEventListener(Event.COMPLETE, onLoad);
			_loader.removeEventListener(ProgressEvent.PROGRESS,loadPregress);
			
			_orgData = _loader.data;
			
			_loaderType = "";
		
			this.dispatchEvent(event);
		}
		
		public function get loadData():*
		{
			return _orgData;
		}
	}
}